package com.http.retrofit;

import com.retrofit.rxjava.MovieSubject;

import java.util.List;

import io.reactivex.Observable;
import io.reactivex.functions.Function;

public class RequestLoader extends ObjectLoader {
    private RequestService requestService;

    public RequestLoader(){
        requestService = RetrofitServiceManager.getInstance().create(RequestService.class);
    }
    /**
     * 获取电影列表
     * @param start
     * @param count
     * @return
     */
    public Observable<List<MovieSubject.SubjectsBean>> getMovie(int start, int count){
        return observe(requestService.getTop250(start , count)).map(new Function<MovieSubject, List<MovieSubject.SubjectsBean>>() {

            @Override
            public List<MovieSubject.SubjectsBean> apply(MovieSubject movieSubject) throws Exception {
                return movieSubject.getSubjects();
            }
        });
    }

    /**
     * 获取城市天气
     * @param cityId
     * @param key
     * @return
     */
    public Observable<String> getWeatherList(String cityId,String key){
        return observe(requestService.getWeather(cityId , key)).map(new Function<String , String>() {
            @Override
            public String apply(String s) throws Exception {
                //可以处理对应的逻辑后在返回
                return s;
            }

        });
    }


}



